package com.gs.wzweather.dao;

import com.gs.wzweather.dao.mapper.StatisticsMapper;
import com.gs.wzweather.entity.Site;
import org.apache.ibatis.annotations.Param;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@Repository
public class StatisticsDao {

    Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    StatisticsMapper mapper;
    SimpleDateFormat sdf = new SimpleDateFormat("HH mm ss SSS");

    /*
    如果用不到水文站之类的就不用传参
    暂时保留参数
  */
    public List<Site> queryWea(String time, String element) {
        int badSite = 0;
        List<Site> sites = null;
        try {
            sites = mapper.queryWea(time, element);
           /* for (Site site : sites) {
                if (site.getWeather().getValue() == null) {
                    badSite++;
                }
                if (badSite > 10) {
                    logger.info("查询最新开始->{}", badSite + " " + sdf.format(new Date()));
                    sites = mapper.queryLatestWea(element);
                    logger.info("查询最新结束->{}", sdf.format(new Date()));
                    break;
                }
            }*/
            return sites;
        } catch (Exception e) {
            logger.info("queryWeather->{}", e.getMessage());
            return null;
        }
    }

   public String queryWeaByStation(String station,String time,String element){
       try {
           return mapper.queryWeaByStation(station,time,element);
       } catch (Exception e) {
           e.printStackTrace();
           return null;
       }
   }
}
